#include <stdio.h>
#include <time.h>

int calculateSumUsingIteration(int n) {
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += i;
    }
    return sum;
}

int calculateSumUsingGauss(int n) {
    return n * (n + 1) / 2;
}

int main() {
    int n = 1000000; // 你可以根据需要更改 n 的值
    clock_t start, end;
    double duration;

    // 逐个累加求解
    start = clock();
    int sumUsingIteration = calculateSumUsingIteration(n);
    end = clock();
    duration = (double)(end - start) / CLOCKS_PER_SEC;
    printf("逐个累加求解的和为：%d，求解时间为：%f 秒\n", sumUsingIteration, duration);

    // 高斯法求解
    start = clock();
    int sumUsingGauss = calculateSumUsingGauss(n);
    end = clock();
    duration = (double)(end - start) / CLOCKS_PER_SEC;
    printf("高斯法求解的和为：%d，求解时间为：%f 秒\n", sumUsingGauss, duration);

    return 0;
}
